package com.wngbms.netty.seatdemo.message;

import lombok.Data;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.channels.FileChannel;

@Data
public class SeatOutMessage {

    private BaseHeader baseHeader;
    private byte[] body;

    private File file;
    private FileChannel fileInChannel;
    private FileInputStream fileInputStream;

    public void setBaseHeader(BaseHeader baseHeader) {
        this.baseHeader = baseHeader;
    }

    public void setBaseHeader(BaseHeader baseHeader, File file) {
        this.baseHeader = baseHeader;
        this.file = file;

        try {
            fileInputStream = new FileInputStream(file);
            fileInChannel = fileInputStream.getChannel();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    public void finish() throws IOException {
        fileInChannel.close();
        fileInputStream.close();
    }
}
